package com.go.smsautosender;


import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class VerifyDialog extends Activity {

	private Context mContext = this;
	
	private EditText mEdtAuthCode;
	private Button mBtnOK;
	private Button mBtnCancel;
	
	private String mAuthCode;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		WindowManager.LayoutParams lpWindow = new WindowManager.LayoutParams();    
        lpWindow.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
        lpWindow.dimAmount = 0.8f;
        getWindow().setAttributes(lpWindow);
         
        setContentView(R.layout.dl_verify);
         
        setTitle("인증 번호 입력");
        
        mAuthCode = getIntent().getExtras().getString("authcode");
        
        mEdtAuthCode = (EditText) findViewById(R.id.verify_AuthCode);
        mBtnOK = (Button) findViewById(R.id.verify_OK);
        mBtnCancel = (Button) findViewById(R.id.verify_Cancel);
        
        mBtnOK.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				String input = mEdtAuthCode.getText().toString();
				if(mAuthCode.equals(input)) {
					SharedPreferences.Editor edit = mContext.getSharedPreferences("TU", Context.MODE_PRIVATE).edit();
					edit.putBoolean("isFirst", false);
					edit.putInt("count", 1);
					edit.commit();
					
					Toast.makeText(mContext, "인증 완료", Toast.LENGTH_SHORT).show();
					finish();
				} else {
					Toast.makeText(mContext, "인증 실패\n다시 입력해주세요", Toast.LENGTH_SHORT).show();
				}
			}
		});
        
        mBtnCancel.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
	}
	
	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
	}
	
	public void setAuthCode(String authCode) {
		mAuthCode = authCode;
	}
}
